'use strict';

/**
 * Redirect 模块
 * 进行redirect跳转
 */

angular.module('metalabPartnerApp').controller('RedirectCtrl', ['$rootScope', '$scope', '$state', '$stateParams', 'MetaRemind', 'MetaResources'
    , function ($rootScope, $scope, $state, $stateParams, MetaRemind, MetaResources) {
        if ($stateParams.module) {
            switch ($stateParams.module) {
                case 'index':
                    $state.go('meta.index', {}, {
                        location: 'replace'
                    });
                    break;
                case 'demandApply':
                    $state.go('meta.demand.apply.step.one', {}, {
                        location: 'replace'
                    });
                    break;
                case 'demandCooperation':
                    $state.go('meta.demand.detail.cooperation.step.one', {demandId: $stateParams.id}, {
                        location: 'replace'
                    });
                    break;
                case 'technologyApply':
                    $state.go('meta.technology.apply.step.one', null, {
                        location: 'replace'
                    });
                    break;
                case 'technologyCooperation':
                    $state.go('meta.technology.detail.cooperation.step.one', {technologyId: $stateParams.id}, {
                        location: 'replace'
                    });
                    break;
                case 'researchSpaceApply':
                    $state.go('meta.demand.apply.step.one', null, {
                        location: 'replace'
                    });
                    break;
                case 'message':
                    $state.go('meta.demand.apply.step.one', null, {
                        location: 'replace'
                    });
                    break;
                case 'myAccount':
                    $state.go('meta.account.info', null, {
                        location: 'replace'
                    });
                    break;
                case 'myTalent':
                    MetaResources.talent.getByUser({
                        userId: '_self'
                    }, function (data) {
                        $state.go('meta.talent.detail.patent', {talentId: data.id}, {
                            location: 'replace'
                        });
                        //$state.go('meta.talent.detail.project', {talentId: data.id});
                    }, function (err) {
                        $state.go($rootScope.previousState.state.name, $rootScope.previousState.params, {
                            location: 'replace'
                        });
                        MetaRemind.warn('出错了', '请先编辑您的主页!');
                    });
                    break;
                case 'myProject':
                    $state.go('meta.project.list.charge', null, {
                        location: 'replace'
                    });
                    break;
                case 'myDemand':
                    $state.go('meta.demand.list.released', null, {
                        location: 'replace'
                    });
                    break;
                case 'myTechnology':
                    $state.go('meta.technology.list.released', null, {
                        location: 'replace'
                    });
                    break;
                case 'editTalent':
                    $state.go('meta.talent.edit', null, {
                        location: 'replace'
                    });
                    break;
            }
        } else {
            MetaRemind.error('缺少模块参数');
            $state.go('meta.index');
        }

    }]);
